package com.huifenqi.saas.client;

import com.huifenqi.common.HfqResponse;
import com.huifenqi.model.Meter;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(value = "smart-service", path = "/smart")
public interface MeterClient {

    @PostMapping(value = "/save/meter")
    HfqResponse saveMeter(@RequestBody Meter meter);

    @GetMapping(value = "/get/meter/{id}")
    HfqResponse getMeter(@PathVariable("id") Integer id);

    @PostMapping(value = "/upload", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},
            consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String upload(@RequestPart(value = "file") MultipartFile file, @RequestParam(value = "fileType") String fileType);

    @GetMapping(value = "/download")
    ResponseEntity<byte[]> download();


    // configuration = MeterClient.MultipartSupportConfig.class
    class MultipartSupportConfig {
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }

}
